package nl.hu.verbrandendephoenix.view;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Statistics extends VerticalPanel {

	private nl.hu.verbrandendephoenix.controller.Statistics controller;
	
	private Label lblTitle;
	private HorizontalPanel pnlButtons, pnlSelect;
	private Button btnDay, btnMonth, btnYear, btnGo;
	private ListBox lbDay, lbMonth, lbYear;
	private VerticalPanel pnlResult;
	
	public Statistics(nl.hu.verbrandendephoenix.controller.Statistics controller) {
		this.controller = controller;
		lblTitle 	= new Label("Top Biedingen");
		lblTitle.addStyleName("h1");
		this.add(lblTitle);
		pnlButtons 	= new HorizontalPanel();
		pnlButtons.setSpacing(5);
		btnDay 		= new Button("Dag");
		btnDay.addClickHandler(this.controller.chBtnDay());
		pnlButtons.add(btnDay);
		btnMonth 	= new Button("Maand");
		btnMonth.addClickHandler(this.controller.chBtnMonth());
		pnlButtons.add(btnMonth);
		btnYear 	= new Button("Jaar");
		btnYear.addClickHandler(this.controller.chBtnYear());
		pnlButtons.add(btnYear);
		this.add(pnlButtons);
		pnlSelect = new HorizontalPanel();
		pnlSelect.setSpacing(5);
		this.add(pnlSelect);
		
		lbDay = new ListBox();
		for(int i = 1; i <= 31; i++) {
			lbDay.addItem(i + "");
		}
		
		lbMonth = new ListBox();
		String[] arrMonths = {"januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"};
		for(int i = 1; i <= 12; i++) {
			lbMonth.addItem(arrMonths[(i-1)], String.valueOf(i));
		}
		lbYear = new ListBox();
		lbYear.addItem(2011 + "");
		
		btnGo = new Button("Go!");
		btnGo.setHeight("20px");
		
		pnlResult = new VerticalPanel();
		this.add(pnlResult);
	}
	public void showDaySelect() {
		pnlSelect.clear();
		pnlSelect.add(lbDay);
		pnlSelect.add(lbMonth);
		pnlSelect.add(lbYear);
		Button btnGo = new Button("Go!");
		btnGo.addClickHandler(controller.chBtnGoDay());
		pnlSelect.add(btnGo);
	}
	public void showMonthSelect() {
		pnlSelect.clear();
		pnlSelect.add(lbMonth);
		pnlSelect.add(lbYear);
		Button btnGo = new Button("Go!");
		btnGo.addClickHandler(controller.chBtnGoMonth());
		pnlSelect.add(btnGo);
	}
	public void showYearSelect() {
		pnlSelect.clear();
		pnlSelect.add(lbYear);
		Button btnGo = new Button("Go!");
		btnGo.addClickHandler(controller.chBtnGoYear());
		pnlSelect.add(btnGo);
	}
	public int getDay() {
		return Integer.parseInt(lbDay.getValue(lbDay.getSelectedIndex()));
	}
	public int getMonth() {
		return Integer.parseInt(lbMonth.getValue(lbMonth.getSelectedIndex()));
	}
	public int getYear() {
		return Integer.parseInt(lbYear.getValue(lbYear.getSelectedIndex()));		
	}
	public VerticalPanel getPanelResult() {
		return pnlResult;
	}
}
